import { stocksum } from "../../http/api";
import {$error} from "../../components/msg/msg"
const state={
    datalist:[],
    echartslist:[]
}
// mutations来修改state
const mutations = {
    changestocksumlist(state,datalist){
        console.log(datalist);
        datalist.forEach(res=>{
            if(!res.sum){
                res.sum=0
            }
        })
        state.datalist = datalist;
        state.echartslist = datalist;
        // this.changeechartlist(state,datalist)
        // context.commit('changestocksumlist',datalist)
    },
    changelist(state,datalist){
        state.datalist = datalist;
    },
    changeechartlist(state,datalist){
        state.echartslist = datalist;
    }
}

const actions = {
    getstocksumlistActions(context){
        // let that=this
        stocksum().then(res=>{
            // console.log(res);
            if (res.status == 201) {
                
                context.commit('changestocksumlist',res.data)
              } else {
                $error(res.message);
                context.commit('changestocksumlist',[])
                
              }
        })
        
    }

}
const getters = {
    datalist(state){
        return state.datalist
    },
    echartslist(state){
        return state.echartslist
    }
}

export default{
    state,
    mutations,
    actions,
    getters,
    namespaced:true,//使用命名空间
}